{* $Id$ *}
{include_core file="admin/lib/header.html" title="发票列表"}
<style>
    /*
    .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
    .ui-timepicker-div dl { text-align: left; }
    .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
    .ui-timepicker-div dl dd { margin: 0px 10px 10px 65px; }
    .ui-timepicker-div td { font-size: 90%; }
    .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
    */
</style>
<div class="page-header border-bottom clearfix">
    <h2 class="left">发票管理<span>在这里对发票进行管理</span></h2>
</div>

<!--search-->
<div class="search-form js_advancedForm" >
    <form action="invoice/admin" method="get" class="js_focusSearchForm">
        <p>
            <label for="" class="search-f-label">公司抬头：</label>
            <input type="text" class="search-f-ipt1" name="search_filter[company_name]" value="{$search_filter.company_name}">
        </p>
        <p>
            <label for="" class="search-f-label">纳税人识别号：</label>
            <input type="text" class="search-f-ipt1" name="search_filter[taxpayer_number]" value="{$search_filter.taxpayer_number}">
        </p>
        <p>
            <label for="" class="search-f-label">合伙人姓名：</label>
            <input type="text" class="search-f-ipt1" name="search_filter[realname]" value="{$search_filter.realname}">
        </p>
        <p>
            <label for="" class="search-f-label">申请时间：</label>
            <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
            <span class="search-f-line"></span>
            <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
        </p>
        <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
</div>

<!--按状态检索-->
<div class="list-table-filters">
    <p>
        <span class="label label-info">按发票类型</span>
        <a href="{AnUrl("invoice/admin?{URLTracker::set("type", -1)}")}" {if $type == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        {foreach invoice_config::$invoice_type as $k => $v}
        <a href="{AnUrl("invoice/admin?{URLTracker::set("type", $k)}")}" {if $type == $k} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
        {/foreach}
    </p>
    <!--
    <p>
        <span class="label label-info">按是否加急</span>
        <a href="{AnUrl("invoice/admin?{URLTracker::set("is_urgen", -1)}")}" {if $is_urgen == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        <a href="{AnUrl("invoice/admin?{URLTracker::set("is_urgen", 0)}")}" {if $is_urgen == 0} class="label label-primary" {else} class="label label-default" {/if}>不加急</a>
        <a href="{AnUrl("invoice/admin?{URLTracker::set("is_urgen", 1)}")}" {if $is_urgen == 1} class="label label-primary" {else} class="label label-default" {/if}>加急</a>
    </p>-->
    <p>
        <span class="label label-info">按状态</span>
        <a href="{AnUrl("invoice/admin?{URLTracker::set("status", -1)}")}" {if $status == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        {foreach invoice_config::$status as $k => $v}
        <a href="{AnUrl("invoice/admin?{URLTracker::set("status", $k)}")}" {if $status == $k} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
        {/foreach}
    </p>
</div>

{include_core file="admin/lib/pager.html"}

<table class="list-table">
    <thead>
        <tr>
            <th style="width:60px;">发票ID</th>
            <th style="min-width: 100px">公司抬头</th>
            <th>发票金额</th>
            <th>实开金额</th>
            <th>发票类型</th>
            <th>纳税人识别号</th><!--
            <th>开票地址</th>
            <th>开票电话</th>
            <th>开票银行名称</th>
            <th>银行账号</th>-->
            <th>合伙人姓名</th>
            <th>合伙人电话</th>
            <th style="min-width: 100px">发票备注</th>
            <th>开票状态</th>
            <th style="min-width: 90px">申请时间</th>
            <th style="min-width: 150px">快递信息</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        {foreach $invoice_list as $k => $v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}" data-price="{$v.price_sum}">
            <td>{$v.id}</td>
            <td>{$v.company_name}</td>
            <td>{$v.price_sum}</td>
            <td>{if $v.actual_price > 0}{$v.actual_price}{/if}</td>
            <td>
                {if $v.type == 1}
                <span class="label label-primary">{invoice_config::$invoice_type[$v.type]}</span>
                {else}
                <span class="label label-warning">{invoice_config::$invoice_type[$v.type]}</span>
                {/if}
            </td>
            <td>{$v.taxpayer_number}</td><!--
            <td>{$v.billing_address}</td>
            <td>{$v.billing_phone}</td>
            <td>{$v.bank_name}</td>
            <td>{$v.bank_number}</td>-->
            <td>{$v.realname}</td>
            <td>{$v.mobile}</td>
            <td>{$v.remark}</td>
            <td>
                {if $v.status == 0}
                <span class="label label-default">{invoice_config::$status[$v.status]}</span>
                {elseif $v.status == 1}
                <span class="label label-warning">{invoice_config::$status[$v.status]}</span>
                {elseif $v.status == 2}
                <span class="label label-success">{invoice_config::$status[$v.status]}</span>
                {elseif $v.status == 3}
                <span class="label label-info">{invoice_config::$status[$v.status]}</span>
                {elseif $v.status == 4}
                <span class="label label-primary">{invoice_config::$status[$v.status]}</span>
                {elseif $v.status == 5}
                <span class="label label-danger">{invoice_config::$status[$v.status]}</span>
                {/if}
            </td>
            <td>{$v.add_time}</td>
            <td>
                {if $v.courier_company_name}
                <p>快递公司:{$v.courier_company_name}</p>
                <p>快递单号:{$v.courier_number}</p>
                <p>快递时间:{date('Y-m-d', strtotime($v.mailed_time))}</p>
                {/if}
            </td>
            <td>
                {if $v.status == 0}
                <a href="{AnUrl("invoice/admin/confirm_pass")}" class="btn btn-warning btn-xs changeStatus-fresh"><i class="icon-edit icon-white"></i>审核通过</a>
                {/if}
                {if $v.status == 0 || $v.status == 1}
                <a href="javascript:;" class="btn btn-primary btn-xs js_confirm_reject"><i class="icon-edit icon-white"><i class="icon-edit icon-white"></i>驳回</a>
                {/if}
                {if $v.status == 1}
                <a href="javascript:;" class="btn btn-primary btn-xs js_confirm_make_invoice"><i class="icon-edit icon-white"><i class="icon-edit icon-white"></i>确认开票</a>
                {/if}
                {if $v.status == 3}
                <a href="javascript:;" class="btn btn-primary btn-xs js_confirm_courier"><i class="icon-edit icon-white"><i class="icon-edit icon-white"></i>填写邮寄信息</a>
                {/if}
                <a href="{AnUrl("invoice/admin/invoice_detail?id={$v.id}")}" class="btn btn-info btn-xs"><i class="icon-edit icon-white"></i>详情</a>
                {if $v.status == 4}
                <a href="javascript:;" class="btn btn-primary btn-xs js_confirm_courier_number"><i class="icon-edit icon-white"><i class="icon-edit icon-white"></i>修改快递单号</a>
                {/if}
            </td>
        </tr>
        {/foreach}
    </tbody>
</table>

<!--快递信息填写弹出层-->
<div class="float-confirm js_confirm_courier_div" style="z-index: 20000; display: none; width:auto;">
    <div class="float-confirm-con">
        <p style="font-size:18px;color:#23a18b;">填写快递信息</p>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div style="width:500px;height:auto;margin-bottom:15px;">
            <table style="line-height:50px;" class="js_payoffTable">
                <tr>
                    <td><span style="color:red;">*</span>快递公司：</td>
                    <td style="min-width:400px;">
                        <input type="text" class="search-f-ipt1" name="courier_company_name" value="">
                    </td>
                </tr>
                <tr>
                    <td><span style="color:red;">*</span>快递单号：</td>
                    <td style="min-width:400px;">
                        <input type="text" class="search-f-ipt1" name="courier_number" value="">
                    </td>
                </tr>
                <tr>
                    <td><span style="color:red;">*</span>邮寄时间：</td>
                    <td style="min-width:400px;">
                        <p><input id="mailed_time" type="text" class="search-f-ipt1" name="mailed_time" value="" readonly></p>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;备注：</td>
                    <td style="min-width:400px;">
                        <textarea name="courier_remark" class="textarea_box addadd-f-area-f-area" style="width: 300px; height:100px;"></textarea>
                    </td>
                </tr>
            </table>
        </div>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div class="float-confirm-btns" style="padding-bottom:30px;">
            <a id="js_confirm_courier_btn" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
            <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
        </div>
    </div>
</div>

<!--实开发票金额填写弹出层-->
<div class="float-confirm js_confirm_make_invoice_div" style="z-index: 20000; display: none; width:auto;">
    <div class="float-confirm-con">
        <p style="font-size:18px;color:#23a18b;">填写实开金额</p>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div style="width:500px;height:auto;margin-bottom:15px;">
            <table style="line-height:50px;" class="js_payoffTable">
                <tr>
                    <td><span style="color:red;">*</span>实开金额：</td>
                    <td style="min-width:400px;">
                        <input type="text" class="search-f-ipt1" name="actual_price" value="">
                    </td>
                </tr>
            </table>
        </div>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div class="float-confirm-btns" style="padding-bottom:30px;">
            <a id="js_confirm_make_invoice_btn" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
            <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
        </div>
    </div>
</div>

<!--修改快递单号弹出层-->
<div class="float-confirm js_confirm_courier_number_div" style="z-index: 20000; display: none; width:auto;">
    <div class="float-confirm-con">
        <p style="font-size:18px;color:#23a18b;">修改快递单号</p>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div style="width:500px;height:auto;margin-bottom:15px;">
            <table style="line-height:50px;" class="js_payoffTable">
                <tr>
                    <td><span style="color:red;">*</span>新快递单号：</td>
                    <td style="min-width:400px;">
                        <input type="text" class="search-f-ipt1" name="update_courier_number" value="">
                    </td>
                </tr>
            </table>
        </div>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div class="float-confirm-btns" style="padding-bottom:30px;">
            <a id="js_confirm_courier_number_btn" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
            <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
        </div>
    </div>
</div>

<!--填写驳回原因-->
<div class="float-confirm js_confirm_reject_div" style="z-index: 20000; display: none; width:auto;">
    <div class="float-confirm-con">
        <p style="font-size:18px;color:#23a18b;">填写驳回原因</p>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div style="width:500px;height:auto;margin-bottom:15px;">
            <table style="line-height:50px;" class="js_payoffTable">
                <tr>
                    <td><span style="color:red;">*</span>驳回原因：</td>
                    <td style="min-width:400px;">
                        <textarea name="reject_remark" class="textarea_box addadd-f-area-f-area" style="width: 300px; height:100px;"></textarea>
                    </td>
                </tr>
            </table>
        </div>
        <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
        <div class="float-confirm-btns" style="padding-bottom:30px;">
            <a id="js_confirm_reject_btn" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
            <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
        </div>
    </div>
</div>

<script>
    /*
    $('#mailed_time').datetimepicker({
        dateFormat: 'yy-mm-dd',
        timeFormat: 'hh:mm:00',
        showButtonPanel: true,
        yearRange: '1900:' + new Date().getFullYear(),
        changeYear:true,
        changeMonth:true,
        maxDate: new Date(),
        yearSuffix: ''
    });*/

    $('#mailed_time').datepicker({
        dateFormat: 'yy-mm-dd',
        showButtonPanel: true,
        yearRange: '1900:'+new Date().getFullYear(),
        changeYear:true,
        changeMonth:true,
        maxDate: new Date(),
        yearSuffix: ''
    });

    //触发弹出快递信息填写页面
    $('.js_confirm_courier').click(function() {
        var invoice_id = $(this).closest('tr').data('id');

        //清空旧数据
        $('input[name="courier_company_name"]').val('');
        $('input[name="courier_number"]').val('');
        $('input[name="mailed_time"]').val('');
        $('textarea[name="courier_remark"]').val('');

        showConfirmDiv($('.js_confirm_courier_div'), invoice_id);
    });

    //触发弹出实开发票金额填写页面
    $('.js_confirm_make_invoice').click(function() {
        var invoice_id = $(this).closest('tr').data('id');
        var price = $(this).closest('tr').data('price');

        //清空旧数据
        $('input[name="actual_price"]').val(price);

        showConfirmDiv($('.js_confirm_make_invoice_div'), invoice_id);
    });

    //触发弹出驳回原因填写页面
    $('.js_confirm_reject').click(function() {
        var invoice_id = $(this).closest('tr').data('id');

        //清空旧数据
        $('textarea[name="reject_remark"]').val('');

        showConfirmDiv($('.js_confirm_reject_div'), invoice_id);
    });

    //触发弹出新快递单号填写页面
    $('.js_confirm_courier_number').click(function() {
        var invoice_id = $(this).closest('tr').data('id');

        //清空旧数据
        $('textarea[name="courier_number"]').val('');

        showConfirmDiv($('.js_confirm_courier_number_div'), invoice_id);
    });

    //关闭弹出层
    $('.js_cancel').click(function() {
        $('.float-confirm').hide();
    });


    //提交快递信息
    $('#js_confirm_courier_btn').click(function() {
        var invoice_id = $('.js_confirm_courier_div').data('id');
        var courier_company_name = $.trim($('input[name="courier_company_name"]').val());
        var courier_number = $.trim($('input[name="courier_number"]').val());
        var mailed_time = $.trim($('input[name="mailed_time"]').val()) + ' 00:00:00';
        var courier_remark  = $.trim($('textarea[name="courier_remark"]').val());

        if (!courier_company_name ||!courier_number || !mailed_time) {
            showMsg('快递信息不完整');
            return false;
        }

        if (isNaN(courier_number)) {
            showMsg('快递单号格式不正确');
            return false;
        }

        $.ajax({
            url: "{AnUrl('invoice/admin/create_courier')}",
            data: {
                "invoice_id": invoice_id,
                "courier_company_name": courier_company_name,
                "courier_number": courier_number,
                "mailed_time": mailed_time,
                "courier_remark": courier_remark
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (data) {
                if (data.flag == 1) {
                    showMsg(data.message);
                } else {
                    showMsg('添加成功');
                    setTimeout(function(){
                        window.location.reload();
                    }, 500);
                }
            }
        });
    });

    //提交实开发票金额信息
    $('#js_confirm_make_invoice_btn').click(function() {
        var invoice_id = $('.js_confirm_make_invoice_div').data('id');
        var actual_price = $.trim($('input[name="actual_price"]').val());

        if (actual_price == '' || actual_price <= 0) {
            showMsg('实开发票金额必填且大于0');
            return false;
        }

        if (isNaN(actual_price)) {
            showMsg('实开发票金额格式不正确');
            return false;
        }

        $.ajax({
            url: "{AnUrl('invoice/admin/confirm_invoice')}",
            data: {
                "id": invoice_id,
                "actual_price": actual_price,
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (data) {
                if (data.flag == 1) {
                    showMsg(data.message);
                } else {
                    showMsg('操作成功');
                    setTimeout(function(){
                        window.location.reload();
                    }, 500);
                }
            }
        });
    });

    //提交驳回原因
    $('#js_confirm_reject_btn').click(function() {
        var invoice_id = $('.js_confirm_reject_div').data('id');
        var reject_remark  = $.trim($('textarea[name="reject_remark"]').val());

        if (!reject_remark) {
            showMsg('驳回原因必填');
            return false;
        }

        $.ajax({
            url: "{AnUrl('invoice/admin/confirm_reject')}",
            data: {
                "id": invoice_id,
                "reject_remark": reject_remark
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (data) {
                if (data.flag == 1) {
                    showMsg(data.message);
                } else {
                    showMsg('驳回成功');
                    setTimeout(function(){
                        window.location.reload();
                    }, 500);
                }
            }
        });
    });

    //提交修改的快递单号
    $('#js_confirm_courier_number_btn').click(function() {
        var invoice_id = $('.js_confirm_courier_number_div').data('id');
        var courier_number  = $.trim($('input[name="update_courier_number"]').val());

        if (!courier_number) {
            showMsg('快递单号必填');
            return false;
        }

        $.ajax({
            url: "{AnUrl('invoice/admin/update_courier_number')}",
            data: {
                "id": invoice_id,
                "courier_number": courier_number
            },
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (data) {
                if (data.flag == 1) {
                    showMsg(data.message);
                } else {
                    showMsg('修改成功');
                    setTimeout(function(){
                        window.location.reload();
                    }, 500);
                }
            }
        });
    });
</script>
{include_core file="admin/lib/pager.html"}
<!--end:列表-->
{include_core file="admin/lib/footer.html"}